// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Globalization;
using AjaxControlToolkit;

[assembly: System.Web.UI.WebResource("GridControl.Resizable.ResizableControlBehavior.js", "text/javascript")]

namespace GridControl
{
    /// <summary>
    /// Class to Extend any control into a resizable element
    /// </summary>
    [Designer("GridControl.ResizableControlDesigner, GridControl")]
    [ClientCssResource("GridControl.yui-ext.css")]
    [ClientScriptResource("GridControl.ResizableControlBehavior", "GridControl.Resizable.ResizableControlBehavior.js")]
    [RequiredScript(typeof(YUI), 1)]
    [RequiredScript(typeof(ext_yui_adapter), 2)]
    [RequiredScript(typeof(YUI_ext), 3)]
    [RequiredScript(typeof(GridExtenstions), 4)]
    [TargetControlType(typeof(Control))]
    [System.Drawing.ToolboxBitmap(typeof(ResizableControlExtender), "GridControl.Resisable.ResizableControl.ico")]
    public class ResizableControlExtender : ExtenderControlBase
    {
     
        private const int MaximumValue = 100000;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ResizableControlExtender"/> class.
        /// </summary>
        public ResizableControlExtender()
        {
            EnableClientState = true;
        }

        /// <summary>
        /// Gets or sets the minimum width of the resizable.
        /// </summary>
        /// <value>The minimum width.</value>
        [ExtenderControlProperty()]
        [DefaultValue(0)]
        public int MinimumWidth
        {
            get
            {
                return GetPropertyValue("MinimumWidth", 0);
            }
            set
            {
                SetPropertyValue("MinimumWidth", value);
            }
        }

        /// <summary>
        /// Gets or sets the minimum height.
        /// </summary>
        /// <value>The minimum height.</value>
        [ExtenderControlProperty()]
        [DefaultValue(0)]
        public int MinimumHeight
        {
            get
            {
                return GetPropertyValue("MinimumHeight", 0);
            }
            set
            {
                SetPropertyValue("MinimumHeight", value);
            }
        }

        /// <summary>
        /// Gets or sets the maximum width.
        /// </summary>
        /// <value>The maximum width.</value>
        [ExtenderControlProperty()]
        [DefaultValue(MaximumValue)]
        public int MaximumWidth
        {
            get
            {
                return GetPropertyValue("MaximumWidth", MaximumValue);
            }
            set
            {
                SetPropertyValue("MaximumWidth", value);
            }
        }

        /// <summary>
        /// Gets or sets the maximum height.
        /// </summary>
        /// <value>The maximum height.</value>
        [ExtenderControlProperty()]
        [DefaultValue(MaximumValue)]
        public int MaximumHeight
        {
            get
            {
                return GetPropertyValue("MaximumHeight", MaximumValue);
            }
            set
            {
                SetPropertyValue("MaximumHeight", value);
            }
        }
        /// <summary>
        /// If the control is also draggable 
        /// </summary>
        [ExtenderControlProperty()]
        public bool Draggable
        {
            get
            {
                return GetPropertyValue<bool>("Draggable", false);
            }
            set
            {
                SetPropertyValue<bool>("Draggable", value);
            }
        }
        /// <summary>
        /// String consisting of the resize handles to display (defaults to false)
        ///<example>
        /// Value   Description
        ///    ------  -------------------
        ///     'n'     north
        ///     's'     south
        ///      'e'     east
        ///      'w'     west
        ///      'nw'    northwest
        ///      'sw'    southwest
        ///      'se'    southeast
        ///      'ne'    northeast
        ///     'all'   all
        /// </example>
        /// </summary>
        [ExtenderControlProperty()]
        public string handles
        {
            get
            {
                return GetPropertyValue<string>("handles", "all");
            }
            set
            {
                SetPropertyValue<string>("handles", value);
            }
        }
        /// <summary>
        /// True to ensure that the resize handles are always visible, 
        /// false to display them only when the user mouses over the 
        /// resizable borders
        /// </summary>
        [ExtenderControlProperty()]
        public bool pinned
        {
            get
            {
                return GetPropertyValue<bool>("pinned", false);
            }
            set
            {
                SetPropertyValue<bool>("pinned", value);
            }
        }
        /// <summary>
        /// True to preserve the original ratio
        /// between height and width during resize (defaults to false)
        /// </summary>
        [ExtenderControlProperty()]
        public bool preserveRatio
        {
   
            get
            {
                return GetPropertyValue<bool>("preserveRatio", false);
            }
            set
            {
                SetPropertyValue<bool>("preserveRatio", value);
            }
        }
        /// <summary>
        /// True for transparent handles.
        /// </summary>
        [ExtenderControlProperty()]
        public bool transparent
        {
            get
            {
                return GetPropertyValue<bool>("transparent", true);
            }
            set
            {
                SetPropertyValue<bool>("transparent", value);
            }

        }
        /// <summary>
        /// True to wrap an element with a div if needed 
        /// (required for textareas and images, defaults to false)
        /// </summary>
        [ExtenderControlProperty()]
        public bool wrap
        {
            get
            {
                return GetPropertyValue<bool>("wrap", false);
            }
            set
            {
                SetPropertyValue<bool>("wrap", value);
            }


        }
        /// <summary>
        /// If the resizing is dynamic
        /// </summary>
        [ExtenderControlProperty()]
        public bool dynamic
        {
            get
            {
                return GetPropertyValue<bool>("dynamic", false);
            }
            set
            {
                SetPropertyValue<bool>("dynamic", value);
            }


        }
    }
}
